<template>
  <el-dialog
    :title="isEdit ? '编辑' : '新增'"
    :visible.sync="dialogVisible"
    width="30%"
  >
    <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      <el-form-item label="姓名" prop="xm">
        <el-input v-model="form.xm"></el-input>
      </el-form-item>
      <el-form-item label="所属组织">
        <el-input disabled v-model="form.zz"></el-input>
      </el-form-item>
      <el-form-item label="职级">
        <el-input disabled v-model="form.zj"></el-input>
      </el-form-item>
      <el-form-item label="职务">
        <el-input disabled v-model="form.zw"></el-input>
      </el-form-item>
      <el-form-item label="岗位">
        <el-input disabled v-model="form.gw"></el-input>
      </el-form-item>
      <el-form-item label="位置层级" prop="cj">
        <el-input-number v-model="form.cj" :step="0.5"></el-input-number>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="dialogVisible = false">取 消</el-button>
      <el-button type="primary" @click="handleSubmit('form')">确 定</el-button>
    </span>
  </el-dialog>
</template>
<script>
export default {
  name: "FormDialog",
  data() {
    return {
      isEdit: false,
      dialogVisible: false,
      form: {
        xm: "",
        zz: "总部机关",
        zj: "副总师级别",
        zw: "主任",
        gw: "||||||||",
        cj: "",
      },
      rules: {
        xm: [{ required: true, message: "请输入姓名", trigger: "blur" }],
        cj: [{ required: true, message: "请输入位置层级", trigger: "blur" }],
      },
    };
  },
  methods: {
    open(status, form) {
      this.dialogVisible = true;
      this.isEdit = status;
      this.form = {
        xm: "",
        zz: "总部机关",
        zj: "副总师级别",
        zw: "主任",
        gw: "||||||||",
        cj: "",
      };
      if (form) {
        this.form = form;
      }
    },
    changeDialogStatus(status) {
      this.dialogVisible = status;
    },
    // 弹窗的保存方法
    handleSubmit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$emit("submit", this.form);
        }
      });
    },
  },
};
</script>
